﻿using System;
using System.Web.Mvc;

namespace Sharp.Platform.Mvc
{
    /// <summary>
    /// 启用模板切换
    /// </summary>
    public class AutomaticTemplateAttribute : ActionFilterAttribute
    {

        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            if (!(filterContext.Result is ViewResultBase))
            {
                base.OnResultExecuting(filterContext);
                return;
            }
            dynamic viewResult = filterContext.Result;


            if (string.IsNullOrEmpty(viewResult.ViewName))
            {
                viewResult.ViewName = TemplateMange.GetTemplate(filterContext.RequestContext, viewResult.Model);
 
                return;
            }


            base.OnResultExecuting(filterContext);
        }

    }
}